﻿Public Class MASCHANGWAT
    Private CHANGWATID As Integer
    Private CHANGWATNAME As String
    Private SelectMaschangwat = Nothing
    Private STATUS = Nothing
    Dim connect As CONDB = CONDB.NewConnection
    Property SelectMaschangwat_() As String
        Get
            SelectMaschangwat = "SELECT `idmaschangwat` as 'รหัส',`changwat` as 'จังหวัด',`status` as 'สถานะการเปิดใช้งาน' FROM cpm.maschangwat; "
            Return SelectMaschangwat
        End Get
        Set(value As String)

        End Set
    End Property
    Property STATUS_() As Boolean
        Get
            Return STATUS
        End Get
        Set(value As Boolean)
            If value = True Then
                STATUS = 1
            Else
                STATUS = 0
            End If
        End Set
    End Property
    Property CHANGWATNAME_() As String
        Get
            Return CHANGWATNAME
        End Get
        Set(value As String)
            CHANGWATNAME = value
        End Set
    End Property
    Property CHANGWATID_() As Integer
        Get
            Return CHANGWATID
        End Get
        Set(value As Integer)
            CHANGWATID = value
        End Set
    End Property
    Public Sub insertMaschangwat()
        If TypeOf CHANGWATNAME Is String Then
            If connect.GetTable("SELECT `changwat` FROM maschangwat WHERE  `changwat` = '" & CHANGWATNAME & "'").Rows.Count > 0 Then
                MsgBox("มีข้อมูลนี้อยู่ในระบบแล้ว", MsgBoxStyle.Critical)
            Else
                connect = CONDB.NewConnection()
                connect.BeginTrans()
                Try
                    Dim sql As String
                    sql = "INSERT INTO cpm.maschangwat"
                    sql += "(`changwat`)"
                    sql += "VALUES ("
                    sql += "'" & CHANGWATNAME & "')"
                    connect.ExecuteNonQuery(sql)
                    connect.CommitTrans()
                    MsgBox("ท่านได้ทำการบันทึกข้อมูลเรียบร้อยแล้ว", MsgBoxStyle.Information)
                Catch ex As Exception
                    connect.RollbackTrans()
                    MsgBox(ex.ToString)
                Finally
                    connect.Dispose()
                End Try
            End If
        Else
            MsgBox("โปรดกรุณาระบุข้อมูลให้ถูกต้อง ต้องเป็นตัวอักษร", MsgBoxStyle.Critical)
        End If
    End Sub
    Public Sub editMaschangwat()
        If TypeOf CHANGWATNAME Is String Then
            connect = CONDB.NewConnection()
            connect.BeginTrans()
            Try
                Dim sql As String
                sql = "UPDATE cpm.maschangwat SET"
                sql += "`changwat` = '" & CHANGWATNAME & "'"
                sql += "WHERE `idmaschangwat` = '" & CHANGWATID & "';"
                connect.ExecuteNonQuery(sql)
                connect.CommitTrans()
                MsgBox("ท่านได้ทำการแก้ไขข้อมูลเรียบร้อยแล้ว", MsgBoxStyle.Information)
            Catch ex As Exception
                connect.RollbackTrans()
                MsgBox(ex.ToString)
            Finally
                connect.Dispose()
            End Try
        Else
            MsgBox("โปรดกรุณาระบุข้อมูลให้ถูกต้อง ต้องเป็นตัวอักษร", MsgBoxStyle.Critical)
        End If
    End Sub
End Class
